package com.bookmngsys.controller;


import com.bookmngsys.dao.BorrowHistoryDao;
import com.bookmngsys.dao.FineHistoryDao;
import com.bookmngsys.dao.ReservationHistoryDao;
import com.bookmngsys.dto.BorrowHistoryDTO;
import com.bookmngsys.entity.FineHistory;
import com.bookmngsys.entity.ReservationHistory;
import com.bookmngsys.utils.Response;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/history")
public class HistoryController {
    @Autowired
    BorrowHistoryDao borrowHistoryDto;
    @Autowired
    ReservationHistoryDao reservationHistoryDao;
    @Autowired
    FineHistoryDao fineHistoryDao;

    @RequestMapping(method = RequestMethod.GET, path = "/getAllReservationHistory")
    @ResponseBody
    @ApiOperation("管理员获得所有人的预约历史")
    Response getAllReservationHistory(){
        try{
            return new Response().success(reservationHistoryDao.getAllReservationHistory());
        }catch (Exception e){
            return new Response().failure(e.getMessage());
        }

    }

    @RequestMapping(method = RequestMethod.GET, path = "/getReservationHistoryByReaderId")
    @ResponseBody
    @ApiOperation("用户获得readerId的预约历史")
    Response getReservationHistoryByReaderId(@RequestAttribute Integer readerId){
        try{
            return new Response().success(reservationHistoryDao.getAllReservationHistoryByReaderId(readerId));
        }catch (Exception e){
            return new Response().failure(e.getMessage());
        }

    }

    @RequestMapping(method = RequestMethod.GET, path = "/getAllBorrowHistory")
    @ResponseBody
    @ApiOperation("管理员获得所有人的借阅历史")
    Response getAllBorrowHistory(){
        try{
            return new Response().success(BorrowHistoryDTO.entityChangeToDTO(borrowHistoryDto.getAllBorrowHistory()));
        }catch (Exception e){
            return new Response().failure(e.getMessage());
        }

    }

    @RequestMapping(method = RequestMethod.GET, path = "/getRBorrowHistoryByReaderId")
    @ResponseBody
    @ApiOperation("用户获得readerId的借阅历史")
    Response getRBorrowHistoryByReaderId(@RequestAttribute Integer readerId){
        try{
            return new Response().success(borrowHistoryDto.getAllBorrowHistoryByReaderId(readerId));
        }catch (Exception e){
            return new Response().failure(e.getMessage());
        }

    }

    @RequestMapping(method = RequestMethod.GET, path = "/getAllFineHistory")
    @ResponseBody
    @ApiOperation("管理员获得所有人的付款历史")
    Response getAllFineHistory(){
        try{
            return new Response().success(fineHistoryDao.getAllFineHistory());
        }catch (Exception e){
            return new Response().failure(e.getMessage());
        }

    }

    @RequestMapping(method = RequestMethod.GET, path = "/getRFineHistoryByReaderId")
    @ResponseBody
    @ApiOperation("用户获得readerId的付款历史")
    Response getRFineHistoryByReaderId(@RequestAttribute Integer readerId){
        try{
            return new Response().success(fineHistoryDao.getAllFineHistoryByReaderId(readerId));
        }catch (Exception e){
            return new Response().failure(e.getMessage());
        }
    }


}
